﻿@{
    ViewBag.Title = "Form";
    Layout = "~/Views/Shared/_ManufactureList.cshtml";
}
<script>
    var currRowId = 1;
    var ifEdit = true;
    $(function () {
        initControl();
        gridList();
        hideEditDiv();
    });
    function initControl() {
        
    }
    function gridList() {
        var $gridList = $("#gridList");
        $gridList.dataGrid({
            url: "/BOM/Manufacture/GetProductionNumberJson",
            postData: $("#form1").formSerialize(),
            height: $(window).height() - 154,
            colModel: [
                { label: '零件编号', name: 'FProductionNO', width: 100, align: 'left', sortable: false },
                { label: '零件名称', name: 'FProductionName', width: 200, align: 'left', sortable: false },
                { label: '剪切条料编号', name: 'StripNO', width: 120, align: 'left', sortable: false },
                { label: '参考图号', name: 'ReferenceName', width: 120, align: 'left', sortable: false },
                { label: '备注说明', name: 'CommentExplain', width: 300, align: 'center', sortable: false },
                { label: '操作人员', name: 'FCreateBy', width: 80, align: 'left', sortable: false },
                { label: '输入日期', name: 'FCreateDate', width: 70, align: 'center', sortable: false },
                { label: '输入时间', name: 'FCreateTime', width: 70, align: 'center', sortable: false },
                { label: '修改人员', name: 'FUpdateBy', width: 80, align: 'left', sortable: false },
                { label: '修改日期', name: 'FUpdateDate', width: 70, align: 'center', sortable: false },
                { label: '修改时间', name: 'FUpdateTime', width: 70, align: 'center', sortable: false },
                { label: '', name: 'FProductionID', width: 120, align: 'center', hidden: true }
            ],
            pager: "#gridPager",
            sortname: 'FProductionNO ASC',
            rownumWidth: 40,
            viewrecords: true,
            loadComplete: function () {
                //hackHeight("#gridList");
                $gridList.jqGrid('setSelection', currRowId);
            },
            onSelectRow: function (rowid) {
                currRowId = rowid;
                var rowData = $gridList.jqGrid('getRowData', rowid);
                setDataByJson("#eidt_div", rowData);
            },
            beforeSelectRow: function (rowid, e) {
                //if (ifEdit) {
                //    return false;
                //}
            }
        });
        $gridList.jqGrid('setLabel', 0, '序号', 'rowNumberHeaderStyle');
        $("#btn_search").click(function () {
            $gridList.jqGrid('setGridParam', {
                postData: $("#form1").formSerialize(),
            }).trigger('reloadGrid');
        });
    }
    function hideEditDiv() {
        if (ifEdit) {
            ifEdit = false;
            $('#eidt_div').hide();
            $('.ui-jqgrid-bdiv').height($('.ui-jqgrid-bdiv').height() + 38);
            //if ($('#btn_edit').hasClass("disabled")) {
            //    $('#btn_edit').removeClass("disabled");
            //}
            $('#btn_list').show();
        }

    }
    function showEditDiv() {
        if (!ifEdit) {
            ifEdit = true;
            $('#eidt_div').show();
            $('.ui-jqgrid-bdiv').height($('.ui-jqgrid-bdiv').height() - 38);
            //if (!$('#btn_edit').hasClass("disabled")) {
            //    $('#btn_edit').addClass("disabled");
            //}
            $('#btn_list').hide();
        }
    }
    function btn_edit() {
        showEditDiv();
    }
    function btn_ok() {
        submitForm();
    }
    function submitForm() {
        if (!$('#form2').formValid()) {
            return false;
        }
        $.submitForm({
            url: "/BOM/Manufacture/SubmitStampingClassForm",
            param: $("#form2").formSerialize(),
            success: function () {
                $("#gridList").jqGrid('setGridParam', {
                    postData: $("#form1").formSerialize(),
                }).trigger('reloadGrid');
            }
        })
    }
    function btn_cancel() {
        hideEditDiv();
    }
    function btn_export() {
        var url = "/Common/ExcelExport?" + init_sql();
        location.href = url;
    }
    function init_sql() {
        var tablename = "V_ZSJ_11_LJ_Production";
        var condition = "UseUnit='@FriendStar.Code.Configs.GetValue("UseUnit")'";
        var cols = [];
        //获取列字段
        var colModel = $("#gridList").jqGrid('getGridParam', 'colModel');
        for (var i = 0; i < colModel.length; i++) {
            var columnHidden = colModel[i].hidden;
            var columnName = colModel[i].name;
            var columnLabel = colModel[i].label;
            if (columnHidden == false && columnName != "rn" && columnName != "") {
                if (columnLabel != '') {
                    cols.push(columnName + ' [' + columnLabel.replace(/<[^>]+>/g, "") + ']');
                } else {
                    cols.push(columnName);
                }
            }
        }
        if ($('#CNFProductionNO').val() != '') {
            condition += " AND (CNFProductionNO LIKE '%" + $('#CNFProductionNO').val() + "%')";
        }
        if ($('#CNFProductionName').val() != '') {
            condition += " AND (CNFProductionName LIKE '%" + $('#CNFProductionName').val() + "%')";
        }
        if ($('#CNReferenceName').val() != '') {
            condition += " AND (CNReferenceName LIKE '%" + $('#CNReferenceName').val() + "%')";
        }
        var sql = "SELECT " + cols.join(',') + " FROM " + tablename + " WHERE " + condition + " ORDER BY FProductionNO ASC";
        return "sql=" + sql;
    }
</script>
<div id="layout" style="height: 100%; width: 100%;">
    <form id="form1">
        <div style="padding: 12px 0 5px 0; padding-left: 15px; border-bottom: 1px solid #ccc;" class="line-table input-width-140">
            <div class="btn-group" style="margin-top:-9px;">
                零件编号<br /><input id="CNFProductionNO" name="CNFProductionNO" type="text" class="form-control" /> &nbsp;
            </div>
            <div class="btn-group" style="margin-top:-9px;">
                零件名称<br /><input id="CNFProductionName" name="CNFProductionName" placeholder="" type="text" class="form-control" /> &nbsp;
            </div>
            <div class="btn-group" style="margin-top:-9px;">
                参考图号<br /><input id="CNReferenceName" name="CNReferenceName" type="text" class="form-control" /> &nbsp;
            </div>
            <div class="btn-group" style="">
                <a id="btn_search" class="btn btn-primary center-block" onclick=""><span class="glyphicon glyphicon-search"></span> 检索</a>
            </div>
            <div id="btn_list" class="btn-group" style="float:right;">
                <a id="" class="btn btn-primary center-block" onclick="$.reload()"><span class="glyphicon glyphicon-refresh"></span> 刷新</a>
                <a id="btn_edit" class="btn btn-primary center-block" onclick="btn_edit()"><span class="glyphicon glyphicon-pencil"></span> 输入</a>
                <a id="btn_export" class="btn btn-primary center-block" onclick="btn_export()"><span class="glyphicon glyphicon-download"></span> 导出</a>
            </div>
        </div>
    </form>
    <form id="form2">
        <table id="eidt_div" class="form" style="margin: 3px 30px 3px 0;">
            <tr>
                <th class="formTitle" style="width:70px;">零件编号</th>
                <td class="formValue" style="width:150px;">
                    <input id="FProductionNO" name="FProductionNO" type="text" class="form-control required" readonly="readonly" value="" />
                    <input id="FProductionID" name="FProductionID" type="text" value="" style="display:none;" />
                </td>
                <th class="formTitle" style="width:80px">零件名称</th>
                <td class="formValue" style="width:150px;">
                    <input id="FProductionName" name="FProductionName" type="text" class="form-control required" readonly="readonly" value="" />
                </td>
                <th class="formTitle" style="width:100px">剪切条料编号</th>
                <td class="formValue" style="width:160px;">
                    <input id="StripNO" name="StripNO" type="text" class="form-control" maxlength="50" value="" />
                </td>
                <th class="formTitle" style="width:80px">参考图号</th>
                <td class="formValue" style="width:160px;">
                    <input id="ReferenceName" name="ReferenceName" type="text" class="form-control" maxlength="50" value="" />
                </td>
                <td>
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <div class="btn-group" style="">
                        <a id="btn_ok" class="btn btn-primary center-block btn-1" onclick="btn_ok()"><span class="glyphicon glyphicon-ok"></span> 确认</a>
                    </div>
                    &nbsp;&nbsp;&nbsp;
                    <div class="btn-group" style="">
                        <a id="btn_cancel" class="btn btn-primary center-block btn-1" onclick="btn_cancel()"><span class="glyphicon glyphicon-remove"></span> 取消</a>
                    </div>
                </td>

            </tr>
        </table>
    </form>
    <div style="">
        <table id="gridList"></table>
        <div id="gridPager"></div>
    </div>
</div>

